public class race implements Runnable {
        private static String winner;
    @Override
    public void run() {
        for (int i = 0; i <= 100; i++) {
            Boolean flag=over(i);
            if (flag){
                break;
            }
            if(Thread.currentThread().getName().equals("兔子")){
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(Thread.currentThread().getName()+"跑了"+i+"步");
        }
    }

    private Boolean over(int step) {
        if(winner!=null){
            return true;
        }
        if (step >= 100) {
            winner=Thread.currentThread().getName();
            System.out.println("winner is "+winner);
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        race r=new race();
        new Thread(r,"兔子").start();
        new Thread(r,"龟").start();

    }
}


